require 'View/UIBase/UIBase'

UICommonOutput = UIBase.New(PanelNames.UICommonOutput)

function UICommonOutput.Init(fun)
    UICommonOutput.callbackFun = fun;
    UIBase.Init(UICommonOutput,func);
end

-- 创建回调
function UICommonOutput:OnCreate()
    self.items = {};
    for i=1, 3 do
        table.insert(self.items, self:GetChild("tipsImprove"..i));
    end
end

-- 显示
function UICommonOutput:OnEnable()
    self:Refresh();
end

function UICommonOutput:Refresh()
    self:UpdateData();
end

function UICommonOutput:UpdateData()
    local lastTableData = logicMgr.MapManager.GetMapcfgByID(logicMgr.MapManager.getLastMapcfg());
    local nowTableData = logicMgr.MapManager.GetMapcfgByID(logicMgr.MapManager.getMapId());
    if lastTableData ~= nil and nowTableData ~= nil then
        local data = {};
        local timeUnit = getLanguage("Sys_OutPut")
        table.insert(data, lastTableData.f_Exp..timeUnit);
        table.insert(data, nowTableData.f_Exp..timeUnit);
        table.insert(data, lastTableData.f_Coin..timeUnit);
        table.insert(data, nowTableData.f_Coin..timeUnit);
        table.insert(data, lastTableData.f_HeroExp..timeUnit);
        table.insert(data, nowTableData.f_HeroExp..timeUnit);
        for i=1, 3 do
            local lastNum = self.items[i]:GetChild("numBefore");
            local nowNum = self.items[i]:GetChild("numAfter");
            lastNum.text = data[i*2-1];
            nowNum.text = data[i*2];
        end

        AudioManager.TryPlaySoundItemChange(CurrencyEnum.MONEY,true)
    else
        self:OnClose();
    end
    local trans = self.fguiObj:GetTransition("appear");
    trans:Play(function ()
        self:OnClose();
    end);
    self:RegisterEvent(Config.EventType.TouchAnyKey,self.OnClose)
end

-- 关闭
function UICommonOutput:OnClose()
    self:UnRegisterEvent(Config.EventType.TouchAnyKey, self.OnClose);
    self:OnBack();
    if self.callbackFun ~= nil then
        self.callbackFun();
    end
end

-- 隐藏
function UICommonOutput:OnDisable()
end

-- 卸载
function UICommonOutput:OnDestroy()
end

return UICommonOutput